import {createSlice} from '@reduxjs/toolkit'
import axios from 'axios'
// const dispath =useDispatch()
const channeltore =createSlice({
    name:'chanel',
    initialState:{
        chanelList:[]
    },
    reducers:{
        setchanelList(state,action){
            state.chanelList=action.payload
        }
    }
})

const {setchanelList}=channeltore.actions
// 异步请求部分

const fetchChanelList=()=>{
    return async(dispath)=>{
        const res=await axios.get('http://geek.itheima.net/v1_0/channels')
        console.log('000',res);
        dispath(setchanelList(res.data.data.channels))
    }
}


export {fetchChanelList}

const reducer =channeltore.reducer

export default reducer